package junitTests;

import com.thoughtworks.selenium.*;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import java.util.regex.Pattern;

public class DownloadingTest extends SeleneseTestCase {
	@Before
	public void setUp() throws Exception {
		selenium = new DefaultSelenium("localhost", 4444, "*chrome", "http://localhost:8888/");
		selenium.start();
	}
	
	@Test
	public void testDownloadCorrectly() throws Exception {
		selenium.open("/login.jsp");
		selenium.type("id=username", "test@gmail.com");
		selenium.type("id=password", "test");
		selenium.click("id=login");
		selenium.waitForCondition("selenium.browserbot.getCurrentWindow().document.getElementById('loginMsgPanel')", "10000");
		selenium.click("link=Continue");
		selenium.waitForPageToLoad("30000");
		assertEquals("Home | Media Vault", selenium.getTitle());
		selenium.click("link=Download");
	}
	
	@Test
	public void testDownloadPicture() throws Exception {
		selenium.open("/login.jsp");
		selenium.type("id=username", "test@gmail.com");
		selenium.type("id=password", "test");
		selenium.click("id=login");
		selenium.waitForCondition("selenium.browserbot.getCurrentWindow().document.getElementById('loginMsgPanel')", "10000");
		selenium.click("link=Continue");
		selenium.waitForPageToLoad("30000");
		assertEquals("Home | Media Vault", selenium.getTitle());
		selenium.click("//div[@id='rp_list']/ul/li[2]/div[4]/a/span");
		selenium.waitForPageToLoad("30000");
		selenium.click("css=div.fileOptions > a > img");
	}
	
	@Test
	public void testDownloadAudio() throws Exception {
		selenium.open("/login.jsp");
		selenium.type("id=username", "test@gmail.com");
		selenium.type("id=password", "test");
		selenium.click("id=login");
		selenium.waitForCondition("selenium.browserbot.getCurrentWindow().document.getElementById('loginMsgPanel')", "10000");
		selenium.click("link=Continue");
		selenium.waitForPageToLoad("30000");
		assertEquals("Home | Media Vault", selenium.getTitle());
		selenium.click("//div[@id='rp_list']/ul/li[2]/div[2]/a/span");
		selenium.waitForPageToLoad("30000");
		selenium.click("css=div.fileOptions > a > img");
	}
	
	@Test
	public void testDownloadVideo() throws Exception {
		selenium.open("/login.jsp");
		selenium.type("id=username", "test@gmail.com");
		selenium.type("id=password", "test");
		selenium.click("id=login");
		selenium.waitForCondition("selenium.browserbot.getCurrentWindow().document.getElementById('loginMsgPanel')", "10000");
		selenium.click("link=Continue");
		selenium.waitForPageToLoad("30000");
		assertEquals("Home | Media Vault", selenium.getTitle());
		selenium.click("//div[@id='rp_list']/ul/li[2]/div[3]/a/span");
		selenium.waitForPageToLoad("30000");
		selenium.click("css=div.fileOptions > a > img");
	}
	
	@Test
	public void testDownloadDocument() throws Exception {
		selenium.open("/login.jsp");
		selenium.type("id=username", "test@gmail.com");
		selenium.type("id=password", "test");
		selenium.click("id=login");
		selenium.waitForCondition("selenium.browserbot.getCurrentWindow().document.getElementById('loginMsgPanel')", "10000");
		selenium.click("link=Continue");
		selenium.waitForPageToLoad("30000");
		assertEquals("Home | Media Vault", selenium.getTitle());
		selenium.click("//div[@id='rp_list']/ul/li[2]/div[5]/a/span");
		selenium.waitForPageToLoad("30000");
		selenium.click("css=div.fileOptions > a > img");
	}

	@After
	public void tearDown() throws Exception {
		selenium.stop();
	}
}
